<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>华米账号-登录</title>
    <link rel="stylesheet" href="../css/pc-ggys.css">
    <link rel="stylesheet" href="../css/login.css">

</head>

<body>
    <div class="b_top">
        <div class="top">
            <div><img src="https://id1.cloud.huawei.com/CAS/static_rss/rss_92/IDMW/common/logos/HUAWEI.svg" alt="">
            </div>
            <div class="mc"><span style="margin: 8px;">丨</span><span>华为商城</span></div>
        </div>
    </div>
    <div class="b_title">
        <div class="title">
            <span>华为账号登录</span>
        </div>
    </div>
    <div class="b_box">
        <div class="box">
            <div class="left">
                <span class="dlm"><img src="../img/ewmtp.jpg" alt=""></span>
                <span>若您使用华为手机，请进入“设置”>“华为帐号”扫码登录。</span>
            </div>
            <div class="zhong">
                <span class="xian"></span>
            </div>
            <div class="right">
                <form action="">
                    <input type="text" class="user" placeholder="手机号/邮件地址/帐号名">
                    <br>
                    <input type="password" class="pwd" placeholder="密码" style="margin-top: 15px;">
                </form>
                <br>
                <a href="../html/00Phone.html" style="margin-right: 150px;">短信验证码登录</a>
                <br>
                <button style="margin:20px 0px">登录</button>
                <div class="qtwt">
                    <span><a href="./02reg.html">注册</a></span>
                    <span>丨</span>
                    <span><a href="">忘记密码</a></span>
                    <span>丨</span>
                    <span><a href="">遇到问题</a></span>
                </div>
            </div>
        </div>
    </div>

    <div class="foot">
        <div class="foot_s">
            <span><a href="">华为帐号用户协议</a></span>
            <span>丨</span>
            <span><a href="">关于华为帐号与隐私的声明</a></span>
            <span>丨</span>
            <span><a href="">常见问题</a> </span>
            <span>丨</span>
            <span><a href="">Cookies</a></span>
            <br>
        </div>
        <div class="foot_x">
            <p>华为帐号 版权所有 © 2011-2022</p>
        </div>
    </div>



    <script src="../js/promise_ajax.js"></script>
    <script src="../js/api.js"></script>
    <script>


        const oBtn = document.querySelector('button');
        const oUser = document.querySelector('.user');
        const oPwd = document.querySelector('.pwd');
        //边输入边判断 两个框都有值 登录高亮
        oUser.oninput = function () {
            if (oUser.value && oPwd.value) {
                oBtn.style.cssText += "background:#ca141d;cursor:pointer;"
            }
            else {
                oBtn.style.cssText += "background:rgba(202,20,29,.5);cursor:not-allowed;"
            }
        }
        oPwd.oninput = function () {
            if (oUser.value && oPwd.value) {
                oBtn.style.cssText += "background:#ca141d;cursor:pointer;"
            } else {
                oBtn.style.cssText += "background:rgba(202,20,29,.5);cursor:not-allowed;"
            }
        }


        oBtn.onclick = async function () {
            const username = oUser.value;
            const userpwd = oPwd.value;
            const usersjh = oUser.value;
            const usereml = oUser.value;

            if (username && userpwd && usersjh && usereml) {
                const res = await login({
                    username,
                    userpwd,
                    usersjh,
                    usereml
                }).then(data => {
                    console.log(data);
                    const { status, msg } = data;
                    if (status) {
                        alert(msg);
                        // 跳转至其他页面
                        // 把登录的账号保存
                        localStorage.setItem('LOGIN_USER', username);
                        //成功之后去哪 从哪来跳哪去
                        const url = location.search.replace('?WZA=', '');
                        if (url) {
                            location.href = url;
                        } else {
                            // location.href = '../html/005列表整合.html';
                            location.href = './06home.html';
                        }

                    } else {
                        alert(msg);
                    }
                })
            }
        }







    </script>

</body>

</html>